<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
            <title>
                Document
            </title>
            <style type="text/css">
                #container{
        width: 400px;
        min-height: 300px;
        background-color: lightgreen;
        margin: auto;
        padding: 10px;
        text-align: center;
    }
    #container li{
        list-style: none;
        text-align: left;
    }
            </style>
            <script src="./jquery.js" type="text/javascript">
            </script>
            <script src="template.js">
            </script>
            <!-- 方法1:自己封装转换时间函数,然后再把转换后的格式传递到template模板中 -->
            <script id="ems" type="text/html">
                <ul>
                    {{each context as value}}
                       <li><span>{{value.time}}</span><div>{{value.desc}}</div></li>
                    {{/each}}
                   </ul>
            </script>
        </meta>
    </head>
</html>
<body>
    <div id="container">
        快递单号：
        <input id="code" name="code" type="text">
            <input id="btn" type="button" value="查询">
                <div id="info">
                </div>
            </input>
        </input>
    </div>
    <script>
        $(function(){
        //方法1:自己封装转换时间函数,然后再把转换后的格式传递到template模板中
        function strToTime(str){
          var date = new Date(str * 1000);
          return date.getFullYear()+'年'+(date.getMonth()+1)+'月'+date.getDay()+'日'+(date.getHours()>12?'下午':'上午')+date.getHours()%12+':'+date.getMinutes()+':'+date.getSeconds();
        }
        $("#btn").click(function(){
            var code = $('#code').val();
            $.ajax({
                type:'get',
                data:{code:code},
                dataType:'jsonp',
                jsonp:'cb',
                url:'ems.php',
                success:function(data){
                    //方法1:自己封装转换时间函数,然后再把转换后的格式传递到template模板中
                    for(var i=0;i<data.data.info.context.length;i++){
                        data.data.info.context[i].time = strToTime(data.data.info.context[i].time);
                    }
                    var tag = template('ems',data.data.info);
                    $('#info').html(tag);
                }
            });
        });
      });
    </script>
</body>
<!-- http://localhost/day05/teacher/cross/ems.php?cb=jQuery111103271766268406078_1509241058101&code=9971121346085&_=1509241058102 -->
<!-- 9971121346085 -->
